<template>
    <div class="drawerContainer">
        <el-form :model="propJson" label-width="auto" style="width: 100%">
            <el-form-item label="上传文件组件类型">
                <el-radio-group v-model="propJson.uploadSelectType">
                    <el-radio label="button">按钮类型</el-radio>
                    <el-radio label="icon">框图类型</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="按钮名称" v-if="propJson.uploadSelectType === 'button'">
                <el-input v-model="propJson.buttonName" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="框图提示内容" v-if="propJson.uploadSelectType === 'icon'">
                <el-input v-model="propJson.buttonName" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="图标大小" v-if="propJson.uploadSelectType === 'icon'">
                <el-input v-model="propJson.iconFontSize" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="图标高度" v-if="propJson.uploadSelectType === 'icon'">
                <el-input v-model="propJson.iconFontHeight" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="文件上传地址">
                <el-input v-model="propJson.upLoadUrl" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="是否对上传文件数量进行限制">
                <el-radio-group v-model="propJson.isUpLoadLimit">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="文件限制数量" v-if="propJson.isUpLoadLimit">
                <el-input-number v-model="propJson.upLoadLimit" :min="1" />
            </el-form-item>

            <el-form-item label="是否展示上传的文件列表">
                <el-radio-group v-model="propJson.isShowFileList">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="列表展示类型" v-if="propJson.isShowFileList">
                <el-select v-model="propJson.listType" placeholder="列表展示类型" style="width: 100%">
                    <el-option label="文本展示" value="text" />
                    <el-option label="图片展示" value="picture" />
                    <el-option label="照片墙方式展示" value="picture-card" />
                </el-select>
            </el-form-item>

            <el-form-item label="是否支持多选文件上传">
                <el-radio-group v-model="propJson.isMultiple">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否支持拖拽上传">
                <el-radio-group v-model="propJson.isDraggable">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否禁用上传">
                <el-radio-group v-model="propJson.isDisabled">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="是否展示Tips">
                <el-radio-group v-model="propJson.isShowTips">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="自定义Tip" v-if="propJson.isShowTips">
                <el-input v-model="propJson.tipInfo" style="width: 100%"/>
            </el-form-item>

            <el-form-item label="是否添加文件大小限制">
                <el-radio-group v-model="propJson.isLimitFileSize">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="文件大小限制" v-if="propJson.isLimitFileSize">
                <el-input v-model="propJson.limitFileSize" style="width: 100%"/>
            </el-form-item>

            <el-divider>添加上传时携带的参数</el-divider>

            <div style="display: flex; justify-content: center; align-items: center; margin-top: 3%;">
                <el-button type="primary" class="addCollapse" size="small" @click="addDataVariable()">添加请求入参</el-button>
            </div>

            <el-form label-width="auto" style="width: 100%">
                <el-collapse>
                    <el-collapse-item :name="paramIndex" v-for="(paramItem, paramIndex) in propJson.uploadDataValue">
                        <template #title>
                            <div class="collapseTitle">
                                <span>参数 {{(paramIndex + 1)}}</span>
                                <el-button type="danger" plain size="small" style="margin-left: 20px" @click.stop="deleteDataVariable(paramIndex)">删除</el-button>
                            </div>
                        </template>
                        <el-form-item label="参数类型">
                            <el-radio-group v-model="paramItem.type">
                                <el-radio label="custom">自定义</el-radio>
                                <el-radio label="variable">关联变量</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="参数名称">
                            <el-input v-model="paramItem.variableName" style="width: 100%"/>
                        </el-form-item>
                        <el-form-item label="参数值" v-if="paramItem.type === 'custom'">
                            <el-input v-model="paramItem.variableValue" style="width: 100%">
                                <template #prepend>
                                    <el-select v-model="paramItem.variableType" placeholder="Select" style="width: 115px">
                                        <el-option label="字符串" value="String" />
                                        <el-option label="数组" value="Array" />
                                        <el-option label="对象" value="Object" />
                                    </el-select>
                                </template>
                            </el-input>
                        </el-form-item>

                        <el-form-item label="变量名称" v-if="paramItem.type === 'variable'">
                            <el-select v-model="paramItem.variableParamName" placeholder="变量名称" style="width: 100%">
                                <el-option v-for="info in commonParam" :label="info.variableName" :value="info.variableName" />
                            </el-select>
                        </el-form-item>
                    </el-collapse-item>
                </el-collapse>
            </el-form>
        </el-form>
    </div>
</template>
<script>
import CommonThirdServiceValue from "@/components/lowcode/service/CommonThirdServiceValue";

export default {
    name: "FileUploadDrawer",
    props: ['commonParam'],
    components: {
        CommonThirdServiceValue,
    },
    methods: {
        addDataVariable() {
            if (!this.propJson.uploadDataValue) {
                this.propJson.uploadDataValue = []
            }
            let variableInfo = {variableName: "", variableValue: "", type: "custom", variableType: "String", variableParamName: ""}
            this.propJson.uploadDataValue.push(variableInfo)
        },
        deleteDataVariable(index) {
            // 删除数组中的数据
            this.propJson.uploadDataValue.splice(index, 1);
        }
    },
    computed: {
        propJson() {
            return this.$store.state.lowCodeDrawerJsonInfo;
        }
    }
}
</script>

<style scoped lang="less">

</style>